﻿/*
 * SshPacketV2.java
 *
 * Created on 2007年7月19日, 下午 12:09
 *
 */

package org.uranus.core.ssh.v2;

import com.sun.kvem.midp.pim.formats.VCalendar10Format;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Random;
import java.util.Vector;
import org.uranus.core.ssh.SshPacket;

/**
 * Copyright 2007 Hsiang-Yu Wang<br>
 * This file is distributed under the terms of the GNU General Public License<br>
 *<br>
 *<pre>
 * --------------------License notice--------------------
 * GNU GENERAL PUBLIC LICENSE
 * Version 3, 29 June 2007
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not,
 * visit: http://www.gnu.org/licenses/gpl.txt
 * --------------------License notice--------------------</pre>
 *  模擬一個符合SSH version 2的packet.
 * @author Hsiang-Yu Wang
 */
public class SshPacketV2 extends SshPacket{
    
    private int offset;
    private Vector buffer;
    
    private int seqnr = 0;
    /** 創建一個"空的"封包, length = 0 */
    public SshPacketV2() {
        super();
        this.offset = 0;
        buffer = new Vector();
        
    }
    /** 當接收到一個ssh封包時, 必須將前5個byte用陣列儲存並使用此constructor宣告<br>
     *  @param in
     *         一個封包的起始5個byte
     *  @see java.io.InputStream
     *  @see org.uranus.core.ssh.SshIO
     */
    public SshPacketV2(int[] in){
        super(in);
    }
    
    public SshPacketV2(byte[] in){
        super(in);
    }
    public int getPacket_length() {
        return super.packet_length;
    }
    
    public int getPadding_length() {
        return super.padding_length;
    }
    public int getPayload_length(){
        return payload.length;
    }
    
    /** 設定packet的length.  <br>
     *  <br>
     *  <font color="red">Warning: 一旦packet length被設定之後, payload將會被初始化</font><br>
     *  @param packet_length
     *         the length of the packet
     */
    public void setPacket_length(int packet_length) {
        super.packet_length = packet_length;
        payload = new byte[packet_length - padding_length - 1];
    }
    /** 設定padding的length.  <br>
     *  <br>
     *  <font color="red">Warning: 一旦padding length被設定之後, padding將會被初始化</font><br>
     *  @param padding_length
     *         the length of padding string.
     */
    public void setPadding_length(int padding_length) {
        super.padding_length = padding_length;
        padding = new byte[padding_length];
    }
    
    /** 將接收到的payload資料儲存到payload array中<br>
     *  <font color="red">Warning: 自定義封包禁用此API, 此API僅供"接收"時使用</font>
     * @param in
     *        接收到的byte資訊
     * @see #addPadding
     * @see #pushString
     */
    public void addPayload(byte in) {
        payload[this.offset++] = in;
    }
    
    /** 將payload以及padding array的指標歸零
     */
    public void resetOffset(){
        this.offset = 0;
    }
    
    /** 將padding string放入padding array當中
     *  @param in
     *         接收到的padding資訊
     *  @see #addPayload
     */
    public void addPadding(byte in) {
        padding[this.offset++] = in;
    }
    
    public void setSeqnr(int seqnr){
        this.seqnr = seqnr;
    }
    
    public int getSeqnr(){
        return seqnr;
    }
    



    

    

    


    


    

 
    
    
 
}
